#!/usr/bin/env python
# -*- coding: UTF-8 -*-
'''
@Project ：henan_sumo
@File ：config40.py
@IDE ：PyCharm
@Author ：xinyingjie
@Date ：2025/5/13 8:52
'''


USE_LIBSUMO = True
USE_GUI = False
SHOW_SIMU = True
KAFKA_HOST = '10.100.12.58:9093'
KAFKA_SEND_TOPIC = "wj_simulation_result_data_sumo"
KAFKA_RECEIVE_TOPIC = "e1_kako_data"

KAFKA_E1_TOPIC = "e1_fusion_data_v8"
KAFKA_E1_TOPIC_SIMU = "e1_fusion_data_v1"
KAFKA_STATUS = "device_up_status"

KAFKA_STATUS = "device_up_status"
RADAR_DATA_LIST = {
                      34: {'sn': 34, 'lon': 113.821658112, 'lat': 34.562413628, 'Downstream': {'sn': 36},
                           'Upstream': None,
                           'disDown': 2393, 'normal': True},
                      36: {'sn': 36, 'lon': 113.815275031, 'lat': 34.541538249, 'Downstream': {'sn': 38},
                           'Upstream': {'sn': 34},
                           'disDown': 1145, 'normal': True},
                      38: {'sn': 38, 'lon': 113.810490264, 'lat': 34.532017004, 'Downstream': {'sn': 18},
                           'Upstream': {'sn': 36},
                           'disDown': 363, 'normal': True},
                      18: {'sn': 18, 'lon': 113.809019865, 'lat': 34.528977466, 'Downstream': {'sn': 20},
                           'Upstream': {'sn': 38},
                           'disDown': 593, 'normal': True},
                      20: {'sn': 20, 'lon': 113.806568569, 'lat': 34.524037319, 'Downstream': {'sn': 22},
                           'Upstream': {'sn': 18},
                           'disDown': 596, 'normal': True},
                      22: {'sn': 22, 'lon': 113.804643991, 'lat': 34.518910304, 'Downstream': {'sn': 24},
                           'Upstream': {'sn': 20},
                           'disDown': 324, 'normal': True},
                      24: {'sn': 24, 'lon': 113.804028033, 'lat': 34.516033499, 'Downstream': {'sn': 26},
                           'Upstream': {'sn': 22},
                           'disDown': 777, 'normal': True},
                      26: {'sn': 26, 'lon': 113.802948288, 'lat': 34.509094823, 'Downstream': {'sn': 28},
                           'Upstream': {'sn': 24},
                           'disDown': 578, 'normal': True},
                      28: {'sn': 28, 'lon': 113.803285954, 'lat': 34.503899314, 'Downstream': {'sn': 30},
                           'Upstream': {'sn': 26},
                           'disDown': 677, 'normal': True},
                      30: {'sn': 30, 'lon': 113.803775624, 'lat': 34.497822559, 'Downstream': {'sn': 32},
                           'Upstream': {'sn': 28},
                           'disDown': 1018, 'normal': True},
                      32: {'sn': 32, 'lon': 113.804504153, 'lat': 34.488680039, 'Downstream': None,
                           'Upstream': {'sn': 30}, 'normal': True},

}

# 全局中心点
GLOBAL_POLYGON_CENTER = [(4448.62, 202.30), (4408.84, 896.84),
                         (3674.53, 890.73), (3738.78, -76.12)]

MAX_SPEED = int(150 / 3.6)
MIN_SPEED = int(30 / 3.6)
CAR_DEFAULT_SPEED = 24
TRUCK_DEFAULT_SPEED = 20
SPECIAL_DEFAULT_SPEED = 18
# 经度逐渐减少
# 感知 第一种出现位置直接发车
# 第二个门架位置进行删车操作

erId_dict = {
    "S001933030055210010": {"lon": 121.159129, "lat": 28.23522},
    "S001933030055210011": {"lon": 121.154497, "lat": 28.238024},  # 删除  all-data没有上报这条数据，就删除
    "S001933030055210012": {"lon": 121.15025, "lat": 28.239659},
    "S001933030055210013": {"lon": 121.144683, "lat": 28.241137},
    "S001933030055210014": {"lon": 121.139778, "lat": 28.24239},
    "S001933030055210015": {"lon": 121.135468, "lat": 28.243534},
    "S001933030055210016": {"lon": 121.128253, "lat": 28.244775},
    "S001933030055210017": {"lon": 121.124437, "lat": 28.244834}}

type_change = {1: 1, 2: 12, 3: 3}
# route_list = ['-6', '-3', '-14', '-0', '-7', '-2', '-11', '-13', '-10', '-5', '-9', '-8', '-1']
route_list = {
    "0": [
        ['80', '74', '9', '85', '84', '-51', '-16', '-10', '-91', '-92', '-105', '-106'],
        ['80', '74', '9', '85', '88', '-44', '-6', '-65', '-92', '-105', '-106'],
        ['80', '74', '9', '13', '12', '-60', '-34', '-41', '-14', '-106'],
        ['80', '74', '9', '13', '-26', '-45', '-41', '-14', '-106'],
    ],
    "1": [
        ['25', '55', '109', '37', '36', '-108', '-27', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '37', '-102', '-75', '-11', '-53', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '71', '-21', '-33', '-2', '-3', '-66', '-99', '-83'],
        ['25', '55', '109', '81', '72', '24', '-93', '-94', '-3', '-66', '-99', '-83'],
    ],
    "2": [
        ['18', '17', '70', '69', '-39', '-57', '-63', '-64', '-96', '-97', '-48', '-47'],
        ['18', '17', '70', '59', '-38', '-101', '-76', '-64', '-96', '-97', '-48', '-47'],
        ['18', '79', '104', '-90', '-46', '-42', '-43', '-97', '-48', '-47'],
        ['18', '79', '104', '68', '73', '-28', '-61', '-0', '-43', '-97', '-48', '-47'],
        ['18', '29', '77', '-22', '-103', '-19', '-30', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-89', '-35', '-40', '-32', '-31', '-58', '-97', '-48', '-47'],
        ['18', '29', '77', '-100', '-82', '-54', '-78', '-31', '-58', '-97', '-48', '-47'],
    ],
}

if __name__ == '__main__':
    # print(list(RADAR_DATA_LIST.keys()))
    # for sn in list(RADAR_DATA_LIST.keys()):
    #     one = RADAR_DATA_LIST[sn]
    #     if one['Downstream']:
    #         print(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #               RADAR_DATA_LIST[one['Downstream']['sn']]['lat'])
    #         print(calculate_distance(one['lon'], one['lat'], RADAR_DATA_LIST[one['Downstream']['sn']]['lon'],
    #                                  RADAR_DATA_LIST[one['Downstream']['sn']]['lat']))
    result = {}
    for RADAR_DATA in RADAR_DATA_LIST:
        # down_sn = {RADAR_DATA['sn'].split("_")[0] + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Downstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) + 1)}
        RADAR_DATA['Upstream'] = {
            'sn': RADAR_DATA['sn'].split("_")[0] + "_" + str(int(RADAR_DATA['sn'].split("_")[1]) - 1)}
        RADAR_DATA['disDown'] = 1000
        RADAR_DATA['normal'] = True
        result[RADAR_DATA['sn']] = RADAR_DATA

    for k, v in result.items():
        if v['Downstream']['sn'] not in result.keys():
            result[k]['Downstream'] = None
        if v['Upstream']['sn'] not in result.keys():
            result[k]['Upstream'] = None
    print(result)
